<template>
  <div class="app-container">
    <!-- <h1>仓库管理</h1> -->
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="mini"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label-width="40" label="仓库编号" prop="code">
        <el-input
          v-model="queryParams.code"
          placeholder="请输入"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label-width="40" label="仓库名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="仓库状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择">
          <el-option label="请选择" :value="null"></el-option>
          <el-option key="IDLE" label="空闲中" value="IDLE"></el-option>
          <el-option key="USED" label="使用中" value="USED"></el-option>
          <el-option key="FULL" label="满仓" value="FULL"> </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:inventory:add']"
          >新增仓库</el-button
        >
      </el-form-item>
    </el-form>

    <el-table
      v-loading="loading"
      :data="InventoryList"
      @selection-change="handleSelectionChange"
      max-height="440"
    >
      <el-table-column label="ID" width="55" align="center" prop="id" />
      <el-table-column
        label="仓库编号"
        align="center"
        :show-overflow-tooltip="true"
        prop="code"
      />
      <el-table-column
        label="仓库名称"
        align="center"
        :show-overflow-tooltip="true"
        prop="name"
      />
      <el-table-column
        label="仓库容量"
        align="center"
        :show-overflow-tooltip="true"
        prop="capacity"
      />
      <el-table-column
        label="库存"
        align="center"
        :show-overflow-tooltip="true"
        prop="stock"
      />
      <el-table-column
        label="库存状态"
        align="center"
        :show-overflow-tooltip="true"
        prop="statusDesc"
      />
      <el-table-column
        width="330px"
        fixed="right"
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            >修改仓库</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-s-tools"
            @click="handleChange(scope.row)"
            >修改库存</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-s-order"
            @click="handleHistory(scope.row)"
            >出入库记录</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-setting"
            @click="handleSetting(scope.row)"
            >预警配置</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <change ref="change" @updataList="handleQuery"></change>
    <history ref="history"></history>
    <woring-config ref="woringConfig"></woring-config>
  </div>
</template>
  
  <script>
import { listInventory } from "@/api/service/inventory";
import NumberFormItem from "@/components/NumberFormItem";
import change from "./components/change.vue";
import history from "./components/history.vue";
import woringConfig from "./components/woring-config.vue";
import { listOnInfo } from "@/api/service/info";
export default {
  components: {
    NumberFormItem,
    change,
    history,
    woringConfig,
  },
  name: "inventory",
  data() {
    return {
      // 重置密码是否展示
      resetPassword: {
        visible: false,
      },
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 产品--主标号表格数据
      InventoryList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        id: null,
        name: null,
        status: null,
        twoCategoryId: null,
        threeCategoryId: null,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询产品--主标号列表 */
    getList() {
      this.loading = true;
      listInventory(this.queryParams).then((response) => {
        console.log(response);
        this.InventoryList = response.data.records;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      // this.reset();
      //   this.open = true;
      //   this.title = "新增主标号";
      this.$router.push({
        path: "/inventory/admin/edit",
      });
    },
    // 预警配置
    handleSetting(row) {
      this.$refs.woringConfig.handelInit(row);
    },
    /* 重置密码*/
    handleChange(row) {
      this.$refs.change.handelInit(row);
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.$router.push({
        path: `/inventory/admin/edit?id=${row.id}`,
      });
    },
    handleHistory(row) {
      this.$refs.history.handelInit(row);
    },
  },
};
</script>
  
  <style lang="scss" scoped>
.edit-form {
  // display: flex;
  .form-label {
    font-size: 14px;
    font-weight: bold;
    line-height: 36px;
    padding-right: 30px;
    .form-red {
      color: #d23c26;
    }
  }
  .form-value {
    display: flex;
    //gap: 30px;
  }
}

::v-deep .el-tabs__content {
  max-height: 500px;
  overflow: auto;
}

.row-item {
  display: flex;
  // gap: 20px;
}
::v-deep .el-form-item__label {
  // width: 240px;
  text-align: right;
}
.form-right ::v-deep .el-input {
  width: 200px;
}
</style>